import { defineStore } from 'pinia';
import { useAutoAction, useAutoGetter } from './autoActionGetter.js';
import { useUserInfoStore } from './userInfo.js';
import { handleCommonRes } from '../utils/resolver.js';
import { netIdsByAreaCode } from '../api/index.js';
import { getStoreId } from './utils.js';

const id = getStoreId('netYardIdsData');
export const netYardIdsDataStore = defineStore(id, {
  state: () => ({
    netYardIds: '', //网约房ids
  }),
  getters: {
    getNetYardIds: useAutoGetter({
      getter: (state) => {
        return state.netYardIds;
      },
      action: function () {
        this.getNetYardIdsByAreaCode();
      },
    }),
  },
  actions: {
    getNetYardIdsByAreaCode: useAutoAction({
      action: async function () {
        const { area_code } = useUserInfoStore();
        const params = { area_code };
        const data = await handleCommonRes(netIdsByAreaCode, params);
        return (this.netYardIds = data);
      },
    }),
  },
});
